//
//  LJMRankSubRoot_Soner_MainTableViewCell.m
//  wind
//
//  Created by 李金明 on 16/1/12.
//  Copyright © 2016年 李金明. All rights reserved.
//

#import "LJMRankSubRoot_Soner_MainTableViewCell.h"
#import "LJMRankSubRoot_Soner_Son_CollectionViewCell.h"
#import "LJMRankSubRoot_Soner_AlbumCollectionViewCell.h"
#import "LJMRankSubRoot_Soner_MVCollectionViewCell.h"
#import "LJMRankSubRoot_Soner_SonerCollectionViewCell.h"
@interface LJMRankSubRoot_Soner_MainTableViewCell () <UICollectionViewDelegate, UICollectionViewDataSource, LJMRankSubRootDelegate, sonerMVDelegete, SonTableViewDelegate, MVTableViewDelegate, AlbumTableViewDelegate, SonerTableViewDelegate>
//sonerCollectionViewCell的协议方法
- (void)changeSonData:(NSMutableArray *)data NSInter:(NSInteger)num;
- (void)tableViewCGFloat:(CGFloat)cgf;
//MVCollectionViewCell的协议方法
- (void)changeMVModel:(LJMRankSubRoot_MVModel *)model;
- (void)MVtableViewCGFloat:(CGFloat)cgf;
//AlbumCollectionViewCell的协议方法
- (void)AlbumtableViewCGFloat:(CGFloat)cgf;
//SonerCollectionViewCell的协议方法
- (void)SonertableViewCGFloat:(CGFloat)cgf;
@property (nonatomic, retain) LJMRankSubRoot_Soner_Son_CollectionViewCell *son_cell;
@property (nonatomic, retain) LJMRankSubRoot_Soner_AlbumCollectionViewCell *album_cell;
@property (nonatomic, retain) LJMRankSubRoot_Soner_MVCollectionViewCell *MV_cell;
@property (nonatomic, retain) LJMRankSubRoot_Soner_SonerCollectionViewCell *soner_Cell;
@property (nonatomic, retain) UICollectionViewFlowLayout *flowLy;
@property (nonatomic, copy) NSString *son_singer_id;
@property (nonatomic, copy) NSString *MV_singer_id;
@property (nonatomic, copy) NSString *album_singer_id;
@property (nonatomic, copy) NSString *soner_singer_id;
@end

@implementation LJMRankSubRoot_Soner_MainTableViewCell
- (void)dealloc
{
    [_MV_singer_id release];
    [_album_singer_id release];
    [_soner_singer_id release];
    [_son_singer_id release];
    [_singer_id release];
    [_flowLy release];
    [_collectionV release];
    [_son_cell release];
    [_album_cell release];
    [_MV_cell release];
    [_soner_Cell release];
    [super dealloc];
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self creatView];
    }
    return self;
}
- (void)creatView
{
    self.backgroundColor = [UIColor whiteColor];

    //添加collectionView
    [self addCollectionView];
}
- (void)layoutSubviews
{
        self.flowLy.itemSize = CGSizeMake(self.frame.size.width, self.frame.size.height - 40);
    self.collectionV.frame = CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height - 40);

}
#pragma 添加个collectionView
- (void)addCollectionView
{
    
    self.flowLy =[[[UICollectionViewFlowLayout alloc] init] autorelease];

    
    self.flowLy.minimumLineSpacing = 0;
    
    self.flowLy.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    self.collectionV = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:self.flowLy];
    self.collectionV.contentOffset = CGPointMake(0, 0);
    
    self.collectionV.delegate = self;
    self.collectionV.dataSource = self;
    self.collectionV.pagingEnabled = YES;
    // 边界反弹效果关,第一页和最后一页不能滑
    self.collectionV.bounces = NO;
//    self.collectionV.contentOffset = CGPointMake(0, 0);
    self.collectionV.showsHorizontalScrollIndicator = NO;
    self.collectionV.showsVerticalScrollIndicator = NO;
    [self.collectionV registerClass:[LJMRankSubRoot_Soner_Son_CollectionViewCell class] forCellWithReuseIdentifier:@"son"];
    [self.collectionV registerClass:[LJMRankSubRoot_Soner_AlbumCollectionViewCell class] forCellWithReuseIdentifier:@"album"];
    [self.collectionV registerClass:[LJMRankSubRoot_Soner_MVCollectionViewCell class] forCellWithReuseIdentifier:@"MV"];
    [self.collectionV registerClass:[LJMRankSubRoot_Soner_SonerCollectionViewCell class] forCellWithReuseIdentifier:@"soner"];
    [self addSubview:self.collectionV];
    [_collectionV release];

    
}
#pragma collectionView的协议方法
#pragma 数量
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 4;
}
#pragma cell
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (0 == indexPath.row) {
        self.son_cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"son" forIndexPath:indexPath];
        if (self.son_singer_id != self.singer_id || nil == self.son_singer_id) {
            self.son_cell.singer_id = self.singer_id;
            self.son_singer_id = self.singer_id;
        }
        self.son_cell.sontableDelegate = self;
        self.son_cell.delegate = self;
        return self.son_cell;
    } else if (1 == indexPath.row) {
        self.album_cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"album" forIndexPath:indexPath];
        if (self.album_singer_id != self.singer_id || nil == self.album_singer_id) {
            self.album_cell.singer_id = self.singer_id;
            self.album_singer_id = self.singer_id;
        }
        self.album_cell.tableDelegate = self;
        return self.album_cell;
    } else if (2 == indexPath.row) {
        self.MV_cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MV" forIndexPath:indexPath];
        if (self.MV_singer_id != self.singer_id || nil == self.MV_singer_id) {
            self.MV_cell.singer_id = self.singer_id;
            self.MV_singer_id = self.singer_id;
        }
        self.MV_cell.MVDelegate = self;
        self.MV_cell.tableDelegate = self;
        return self.MV_cell;
    } else {
        self.soner_Cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"soner" forIndexPath:indexPath];
        if (self.soner_singer_id != self.singer_id || nil == self.soner_singer_id) {

            self.soner_Cell.singer_id = self.singer_id;
            self.soner_singer_id = self.singer_id;
        }
        self.soner_Cell.sonerTableDelegate = self;
        return self.soner_Cell;
    }
    
    
    
}

#pragma 跟(小白条)的随动
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if (scrollView == self.collectionV) {
        CGFloat n = scrollView.contentOffset.x / self.bounds.size.width;
        [self.collectdelegate changeCGFloat:n];

    }
}
#pragma 减速结束后的方法
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    if (scrollView == self.collectionV) {
        NSInteger n = scrollView.contentOffset.x / self.frame.size.width;
        [self.collectdelegate changeButton:n];
        
    }
}
//son的协议方法 
- (void)changeSonData:(NSMutableArray *)data NSInter:(NSInteger)num
{
    [self.changeDeldegate changeSonData:data NSInter:num];
}
#pragma son改变坐标的方法
- (void)tableViewCGFloat:(CGFloat)cgf
{
    [self.changeTableView tableViewCGFloat:cgf];
}
#pragma MV的协议方法
- (void)changeMVModel:(LJMRankSubRoot_MVModel *)model
{
    [self.changeMVDeldegate changeMVModel:model];
}
#pragma MV改变坐标的方法
- (void)MVtableViewCGFloat:(CGFloat)cgf
{
    [self.changeTableView tableViewCGFloat:cgf];
}
#pragma Album的坐标改变的方法
- (void)AlbumtableViewCGFloat:(CGFloat)cgf
{
    [self.changeTableView tableViewCGFloat:cgf];
}
#pragma Soner的坐标改变的方法
- (void)SonertableViewCGFloat:(CGFloat)cgf
{
[self.changeTableView tableViewCGFloat:cgf];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
